# -*- coding: utf-8 -*-
#  @author  Bink
#  @date  2020/8/29 21:41
# @Email : 2641032316@qq.com


# TODO 向目录：E:/study/

import os
import shutil

fileDir = './study/linux'
filePath2 = './study/1.txt'

if os.path.exists(filePath2):
    os.remove(filePath2)

#  （1）创建目录：linux
if not os.path.exists(fileDir):
    os.makedirs(fileDir)

#  （2）在目录下创建1.txt，写入good afternoon!
with open(filePath2, 'w+', encoding='utf8') as file:
    file.write('good afternoon!')

#  （3）将1.txt备份移动到linux目录中。
filePath3 = './study/linux/1.txt'
with open(filePath3, 'w+', encoding='utf8') as file:
    with open(filePath2, 'r', encoding='utf8') as file_old:
        file.writelines(file_old.readlines())

#  （4）将1.txt从linux目录恢复到E:/study/下，并删除linux文件夹
filePath4 = './study/1.txt'
with open(filePath4, 'w+', encoding='utf8') as file:
    with open(filePath3, 'r', encoding='utf8') as file_old:
        file.writelines(file_old.readlines())
shutil.rmtree(fileDir)

#  （5）将1.txt删除
filePath5 = './study/1.txt'
os.remove(filePath5)



